package com.lihui.exercises;

import com.lihui.dao.StudentDao;
import com.lihui.model.Student;

import java.text.MessageFormat;
import java.util.List;
import java.util.Scanner;

/**
 * 功能描述
 *
 * @author wileda
 * @date 2022/12/28  18:58
 */
public class Exe_02 {
    public static void main(String[] args) {
        while (true){
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入学生姓名：");
            String studentName = scanner.nextLine();
            if(studentName == null || studentName.equals("")){
                System.out.println("输入学生的姓名为空");
                return;
            }
            StudentDao studentDao = new StudentDao();
            List<Student> students = studentDao.selectByName(studentName);
            if(students == null || students.size() == 0){
                System.out.println("没有找到对应学生信息 ---->" + studentName);
                return;
            }
            for (Student student: students) {
                String info = MessageFormat.format("编号: {0}\t| 学号: {1}\t| 姓名: {2}\t | " +
                                "邮箱: {3}\t| 班级编号: {4}", student.getId(), student.getSn(), student.getName(),
                        student.getMail(), student.getClassesId());
                System.out.println(info);
            }

            System.out.println("请输入要调班学生编号");
            int studentId = scanner.nextInt();
            System.out.println("请输入要调入班级编号");
            int classesId = scanner.nextInt();
            int result = studentDao.updateClassesId(studentId,classesId);
            if(result > 0){
                System.out.println("调班成功");
            }else {
                System.out.println("调班失败");
            }
        }
    }
}
